/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ParticipantDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Participant;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author eichawsan
 */
public class ParticipantDAOImpl extends AbstractDAO implements ParticipantDAO{

    public ParticipantDAOImpl(){
        super();
    }
    @Override
    public Participant findParticipant (String conferenceName,String userName) throws HibernateAccessLayerException {
      try {  
         return ((List<Participant>)(this.findByCustomizeQuery(Participant.class, "conferenceName='"+conferenceName+"' and userName='"+userName+"'"))).get(0);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
    public List<Participant> findAllParticipant() throws HibernateAccessLayerException {
        try {
            List result =   super.findAll(Participant.class);
            return (result);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
    
    @Override
    public void insertParticipant(Participant participant) throws HibernateAccessLayerException {
        try {
          //  // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Inserting Participant" + participant.getId());
            super.saveOrUpdate(participant);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
    @Override
    public void updateParticipant(Participant participant) throws HibernateAccessLayerException {
         try {
        //    // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Updating Participant" + participant.getId());
            super.saveOrUpdate(participant);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
    public void deleteParticipant(Participant participant) throws HibernateAccessLayerException {
        try {
            super.delete(participant);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Participant> findParticipantByConferenceName(String conferenceName) throws HibernateAccessLayerException {
        try {  
         return (List<Participant>)
                 this.findByCustomizeQuery(Participant.class, "conferenceName='"+conferenceName+"'");
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Participant> findParticipantByUserName(String userName) throws HibernateAccessLayerException {
         try {  
         return (List<Participant>)this.findByCustomizeQuery(Participant.class, " userName='"+userName+"'");
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public List<Participant> findByCustomizeQuery(String queryString) throws HibernateAccessLayerException {
        try {  
         return (List<Participant>)this.findByCustomizeQuery(Participant.class,queryString);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

}
